//
//  TodayOrderCell.m
//  Doctor
//
//  Created by 阳光 on 16/9/8.
//  Copyright © 2016年 阳光. All rights reserved.
//  今日预约

#import "TodayOrderCell.h"

@interface TodayOrderCell ()
@end



@implementation TodayOrderCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self=[super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        self.backgroundColor=MAIN_BACK_COLOR;
        
         self.bgView.hidden=NO;
        
         self.topLine.hidden=NO;
        
        self.cnameLabel.font=Font_Number(16);
        
        self.enameLabel.font=Font_Number(16);
        
        self.sexLabel.font=Font_Number(16);
        
        self.ageLabel.font=Font_Number(16);
        
        self.sexLine.hidden=NO;
        
        self.ageLine.hidden=NO;
        
        self.nameLine.hidden=NO;
        
        self.timeLabel.font=Font_Number(16);
        
        self.timeLine.hidden=NO;
        
        self.detailLabel.font=Font_Number(16);
        
        self.videoBtn.hidden = NO;//.
        
    }
    return self;
}


-(UIView *)bgView
{
    if (_bgView==nil) {
        _bgView=[UIView new];
        [self.contentView addSubview:_bgView];
        [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(kmargin);
            make.right.left.bottom.mas_equalTo(0);
        }];
        _bgView.backgroundColor=WhiteColor;
    }
    return _bgView;
}

-(UIView *)topLine
{
    if (_topLine==nil) {
        _topLine=[UIView new];
        [self.bgView addSubview:_topLine];
        [_topLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(0);
            make.size.mas_equalTo(CGSizeMake(APPW,2));
        }];
        _topLine.backgroundColor=Main_Color;
    }
    return _topLine;
}

// cnameLabel
-(UILabel *)cnameLabel
{
    if (!_cnameLabel) {
        _cnameLabel=[self getLabelWithText:@"张三" font:Font_Number(16) textColor:Color212121 textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
        [self.bgView addSubview:_cnameLabel];
        [_cnameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.mas_equalTo(kmargin);
            make.right.mas_equalTo(self.enameLabel.mas_left).offset(-kmargin);
        }];
    }
    return _cnameLabel;
}

// enameLabel
-(UILabel *)enameLabel
{
    if (!_enameLabel) {
        _enameLabel=[self getLabelWithText:@"zhangsan" font:Font_Number(16) textColor:Color212121 textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
        [self.bgView addSubview:_enameLabel];
        [_enameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(self.cnameLabel.mas_right).offset(kmargin);
            make.centerY.mas_equalTo(self.cnameLabel.mas_centerY);
        }];
    }
    return _enameLabel;
}

-(UIView *)ageLine
{
    if (_ageLine==nil) {
        _ageLine=[UIView new];
        [self.bgView addSubview:_ageLine];
        [_ageLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.ageLabel.mas_left).offset(-kmargin);
            make.top.mas_equalTo(self.bgView.mas_top).offset(kmargin);
            make.width.mas_equalTo(1);
            make.height.mas_equalTo(25);
        }];
        _ageLine.backgroundColor=ColorE5E5E5;
    }
    return _ageLine;
}

// ageLabel
-(UILabel *)ageLabel
{
    if (!_ageLabel) {
        _ageLabel=[self getLabelWithText:@"24岁" font:Font_Number(16) textColor:Color212121 textAlignment:NSTextAlignmentRight lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
        [self.bgView addSubview:_ageLabel];
        [_ageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-kmargin);
            make.centerY.mas_equalTo(self.cnameLabel.mas_centerY);
            make.left.mas_equalTo(self.ageLine.mas_right).offset(kmargin);
        }];
    }
    return _ageLabel;
}

-(UIView *)sexLine
{
    if (_sexLine==nil) {
        _sexLine=[UIView new];
        [self.bgView addSubview:_sexLine];
        [_sexLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.sexLabel.mas_left).offset(-kmargin);
            make.top.mas_equalTo(self.bgView.mas_top).offset(kmargin);
            make.width.mas_equalTo(1);
            make.height.mas_equalTo(25);
        }];
        _sexLine.backgroundColor=ColorE5E5E5;
    }
    return _sexLine;
}

// sexLabel
-(UILabel *)sexLabel
{
    if (!_sexLabel) {
        _sexLabel=[self getLabelWithText:@"女" font:Font_Number(16) textColor:Color212121 textAlignment:NSTextAlignmentRight lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
        [self.bgView addSubview:_sexLabel];
        [_sexLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(self.ageLine.mas_left).offset(-kmargin);
            make.centerY.mas_equalTo(self.cnameLabel.mas_centerY);
            make.left.mas_equalTo(self.sexLine.mas_right).offset(kmargin);
        }];
    }
    return _sexLabel;
}

-(UIView *)nameLine
{
    if (_nameLine==nil) {
        _nameLine=[UIView new];
        _nameLine.backgroundColor=MAIN_BACK_COLOR;
        [self.bgView addSubview:_nameLine];
        [_nameLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.cnameLabel.mas_bottom).offset(kmargin);
            make.size.mas_equalTo(CGSizeMake(APPW,.5));
        }];
    }
    return _nameLine;
}

// timeLabel
- (UILabel *)timeLabel
{
    if (!_timeLabel) {
        
        _timeLabel=[self getLabelWithText:@"2016-08-22 11:40-12:10" font:Font_Number(16) textColor:Color333333 textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
        [self.bgView addSubview:_timeLabel];
        
        //@"预约时间"
        UILabel *leftTimeLabel=[self getLabelWithText:NSLocalizedString(@"AppointmentTime", nil) font:Font_Number(16) textColor:Color999999 textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
        [self.bgView addSubview:leftTimeLabel];
        [leftTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(kmargin);
            make.top.mas_equalTo(self.nameLine.mas_bottom).offset(kmargin);
        }];
        
        [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(leftTimeLabel.mas_right).offset(kmargin);
            make.centerY.mas_equalTo(leftTimeLabel.mas_centerY);
        }];
        
    }
    return _timeLabel;
}

-(UIView *)timeLine
{
    if (_timeLine==nil) {
        _timeLine=[UIView new];
        _timeLine.backgroundColor=MAIN_BACK_COLOR;
        [self.bgView addSubview:_timeLine];
        [_timeLine mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.timeLabel.mas_bottom).offset(kmargin);
            make.size.mas_equalTo(CGSizeMake(APPW,.5));
        }];
    }
    return _timeLine;
}

// detailLabel
- (UILabel *)detailLabel
{
    if (!_detailLabel) {
        
        _detailLabel=[self getLabelWithText:@"姨妈长时间不来,小腹涨疼,吃饭没有胃口" font:Font_Number(16) textColor:Color333333 textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:0];
        
        //@"病情描述"
        UILabel *leftDetailLabel=[self getLabelWithText:NSLocalizedString(@"Description", nil) font:Font_Number(16) textColor:Color999999 textAlignment:NSTextAlignmentLeft lineBreakMode:NSLineBreakByCharWrapping numberOfLines:1];
        [self.bgView addSubview:leftDetailLabel];
        [leftDetailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(kmargin);
            make.top.mas_equalTo(self.timeLine.mas_bottom).offset(kmargin);
        }];
        
        [self.bgView addSubview:_detailLabel];
        [_detailLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(leftDetailLabel.mas_right).offset(kmargin);
//            make.right.mas_equalTo(-kmargin/2);
//            make.top.mas_equalTo(leftDetailLabel.mas_top);
            make.top.mas_equalTo(self.timeLine.mas_bottom).offset(kmargin);
        }];
    }
    return _detailLabel;
}




//.
- (void)configureFirstCellWithModel:(FirstConsultModel *)model{
    
    self.cnameLabel.text = model.name;
    
    self.enameLabel.text = model.en_name;
    
    
    BOOL isCN = [[LanguageConvert alloc] hasShownIsCnOrNot];
    if (isCN == YES) {
        self.sexLabel.text = model.cn_garden;
    } else if (isCN == NO){
        self.sexLabel.text = model.en_garden;
    }
    
    
    self.ageLabel.text = [NSString stringWithFormat:@"%@%@", model.years, NSLocalizedString(@"Years", nil)];//@"%@岁",
    
    self.detailLabel.text = model.descriptionStr;
    
    
    
    NSString *startTime = [self getConvertToDateByTimeStamp:model.optimum_time];
    
    NSString *stopTime = [self getConvertToDateByTimeStamp:model.end_time];
    
    NSArray *startArr = [startTime componentsSeparatedByString:@" "];
    
    NSArray *stopArr = [stopTime componentsSeparatedByString:@" "];
    
    NSString *timeStr = [[NSString alloc] init];
    
    if ([startArr[0] isEqualToString:stopArr[0]]) {
        
        timeStr = [NSString stringWithFormat:@"%@ %@-%@", startArr[0], startArr[1], stopArr[1]];
    }
    self.timeLabel.text = timeStr;
    
    
    
    if ([model.tv_status isEqualToString:@"1"]) {
        [self.videoBtn setImage:[UIImage imageNamed:@"icon_video1"] forState:UIControlStateNormal];
    } else {//if ([model.tv_status isEqualToString:@"0"])
        [self.videoBtn setImage:[UIImage imageNamed:@"icon_video2"] forState:UIControlStateNormal];
    }
    

}

//时间戳转时间
- (NSString *)getConvertToDateByTimeStamp:(NSString *)timeStamp{
    
    NSDateFormatter *formatter=[[NSDateFormatter alloc]init];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    
    NSTimeZone* timeZone = [NSTimeZone systemTimeZone];
    [formatter setTimeZone:timeZone];
    [formatter setDateFormat:@"YYYY-MM-dd HH:mm"];
    
    NSDate * currentDate = [NSDate dateWithTimeIntervalSince1970:[timeStamp longLongValue]];
    NSString * formDateStr = [formatter stringFromDate:currentDate];
    //NSLog(@"formDateStr :%@",formDateStr);
    
    return formDateStr;
}


-(UIButton *)videoBtn{
    
    if (!_videoBtn) {
        _videoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        //_videoBtn.backgroundColor=[UIColor yellowColor];
        _videoBtn.frame = CGRectMake(__KScreenWidth-50, 55, 30, 20);
        [self.bgView addSubview:_videoBtn];
        [_videoBtn setImage:[UIImage imageNamed:@"icon_video2"] forState:UIControlStateNormal];
    }
    return _videoBtn;
}
//.



@end
